﻿using Prism.Ioc;
using Prism.Modularity;
using StarryEdge.Core;
using StarryEdge.Core.Device;
using StarryEdge.Core.Manager;
using StarryEdge.Core.Parameter;
using StarryEdge.Core.Tool;
using StarryEdge.Devices;
using StarryEdge.Domains;
using StarryEdge.Parameter;
using StarryEdge.Plugin;
using StarryEdge.Views;
using StarryEdge.WPF.Lang;
using System;
using System.IO;
using System.Windows;

namespace StarryEdge
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            var device_path = $"{Environment.CurrentDirectory}\\init";
            if (!Directory.Exists(device_path))
            {
                Directory.CreateDirectory(device_path);
            }
            LangManager.SetLang("cn");
            _ = log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.Combine(Environment.CurrentDirectory, "log4net.config")));
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<ILangProvider, Domains.LangProvider>();
            containerRegistry.RegisterSingleton<IStarryEdgeLog, Domains.StarryEdgeLog>();
            containerRegistry.RegisterSingleton<IDialogHost, Domains.DialogStarryEdge>();
            containerRegistry.RegisterSingleton<ICompressionDecompression, ZIP7>();
            containerRegistry.RegisterSingleton<ITaskManager, TaskManager>();
            containerRegistry.RegisterSingleton<IPluginManager, PluginManager>();
            containerRegistry.RegisterSingleton<IObjectManager, ObjectContainer>();
            containerRegistry.RegisterSingleton<ITemporaryParameter, TemporaryParameter>();
            containerRegistry.RegisterSingleton<ISystemConfigParameter, SystemConfigParameter>();
            containerRegistry.RegisterSingleton<IDeviceInfoManage, DeviceInfoManage>();
            containerRegistry.RegisterSingleton<IDeviceFactory, DeviceFactory>();
            containerRegistry.RegisterSingleton<IUserEntity, UserEntity>();
            containerRegistry.RegisterSingleton<IUIRoleManage, UIRoleManage>();
            containerRegistry.Register<IMenuUpdate, MenuUpdate>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) //配置模块目录
        {
            moduleCatalog.AddModule<StarryEdge.Menu.User.UserModule>();
            moduleCatalog.AddModule<StarryEdge.Menu.SettingSystem.SettingSystemModule>();
            moduleCatalog.AddModule<StarryEdge.Menu.Device.DeviceModule>();
            moduleCatalog.AddModule<StarryEdge.Menu.LogSystem.LogSystemModule>();
        }
    }
}
